package com.usefullc.extinguisher.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.usefullc.common.enums.ValidActionEnum;
import com.usefullc.extinguisher.query.FireDeviceQuery;
import com.usefullc.system.validator.UsefulValid;
import com.usefullc.extinguisher.domain.FireDeviceAuditRecord;
import com.usefullc.extinguisher.param.FireDeviceAuditRecordParam;
import com.usefullc.extinguisher.vo.FireDeviceAuditRecordVo;
import com.usefullc.extinguisher.query.FireDeviceAuditRecordQuery;
import com.usefullc.extinguisher.service.FireDeviceAuditRecordService;
import com.usefullc.common.util.BeanUtils;
import com.usefullc.system.controller.BaseController;
import com.usefullc.system.controller.WebResultBuilder;
import com.usefullc.system.entity.Pager;
import com.usefullc.system.entity.WebResult;
import com.usefullc.system.param.IdsParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import static com.usefullc.system.controller.WebResultBuilder.successResult;

/**
 * 设备检查作业记录控制类
 * @author: 星空
 * @date: 2022-09-08
 */
@RestController
@RequestMapping("/extinguisher/fireDeviceAuditRecord/")
@Api( tags="设备检查作业记录")
public class FireDeviceAuditRecordController extends BaseController {

    @Autowired
    private FireDeviceAuditRecordService fireDeviceAuditRecordService;

    @ApiOperationSupport(author = "Sampson@usefullc.com")
    @ApiOperation(value = "设备检查作业记录列表",response = WebResult.class)
    @GetMapping(path = "list",produces = "application/json")
    public WebResult list(@UsefulValid(query = true) FireDeviceAuditRecordQuery query) {
//        Pager<FireDeviceAuditRecordVo> page = fireDeviceAuditRecordService.findVoByPage(query);
        Pager<FireDeviceAuditRecordVo> page = fireDeviceAuditRecordService.findNewByPage(query);
        return WebResultBuilder.successResult(page);
    }

    @ApiOperationSupport(author = "Sampson@usefullc.com")
    @ApiOperation(value = "设备检查作业记录所有列表", response = WebResult.class)
    @GetMapping(path = "listAll", produces = "application/json")
    public WebResult listAll(@UsefulValid(query = true) FireDeviceAuditRecordQuery query) {
        List<FireDeviceAuditRecord> dataList = fireDeviceAuditRecordService.findAll(query);
        return WebResultBuilder.successResult(dataList);
    }


    @ApiOperationSupport(author = "Sampson@usefullc.com")
    @ApiOperation(value = "设备检查作业记录详情",response = WebResult.class)
    @GetMapping(path = "detail",produces = "application/json")
    public WebResult detail(@ApiParam(value = "示例ID") @Valid @RequestParam Long id) {
        FireDeviceAuditRecord fireDeviceAuditRecord = fireDeviceAuditRecordService.findById(id);
        return WebResultBuilder.successResult(fireDeviceAuditRecord);
    }


    @ApiOperationSupport(author = "Sampson@usefullc.com")
    @ApiOperation(value = "创建设备检查作业记录", response = WebResult.class)
    @PostMapping(path = "/save", produces = "application/json")
    @UsefulValid
    public WebResult save(@UsefulValid(save=true) @RequestBody FireDeviceAuditRecordParam param) {
        FireDeviceAuditRecord fireDeviceAuditRecord = BeanUtils.beanCopy(param, FireDeviceAuditRecord.class);
        return successResult(fireDeviceAuditRecordService.save(fireDeviceAuditRecord));
    }

    @ApiOperationSupport(author = "Sampson@usefullc.com")
    @ApiOperation(value = "修改设备检查作业记录", response = WebResult.class)
    @PostMapping(path = "/update", produces = "application/json")
    public WebResult update(@UsefulValid(update=true) @RequestBody FireDeviceAuditRecordParam param) {
        FireDeviceAuditRecord oldBean = fireDeviceAuditRecordService.findById(param.getId());
        BeanUtils.beanCopy(param, oldBean);
        return successResult(fireDeviceAuditRecordService.update(oldBean));
    }

    @ApiOperationSupport(author = "Sampson@usefullc.com")
    @PostMapping(path = "del",produces = "application/json")
    @ApiOperation(value = "删除设备检查作业记录",response = WebResult.class)
    public WebResult del(@UsefulValid(del=true) @RequestBody IdsParam idParam) {
        fireDeviceAuditRecordService.delete(idParam.getIds());
        return WebResultBuilder.successResult();
    }

    @ApiOperationSupport(author = "Sampson@usefullc.com")
    @PostMapping(path = "delByLogic",produces = "application/json")
    @ApiOperation(value = "逻辑删除设备检查作业记录",response = WebResult.class)
    public WebResult delByLogic(@UsefulValid(del=true) @RequestBody IdsParam idParam) {
        fireDeviceAuditRecordService.delete(idParam.getIds());
        return WebResultBuilder.successResult();
    }

    @ApiOperationSupport(author = "Sampson@usefullc.com")
    @ApiOperation(value = "消防设备检查明细导出",response = WebResult.class)
    @GetMapping(path = "exportExcel",produces = "application/json")
    public void exportExcel(@UsefulValid(query = true) FireDeviceAuditRecordQuery query, HttpServletResponse response) {
        fireDeviceAuditRecordService.export(query,response);
    }






}
